package com.ruoyi.web.controller.modules;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.file.PlanFileUtils;
import com.sdstc.modules.eneity.PlanFileEntity;
import com.sdstc.modules.query.PlanFileQuery;
import com.sdstc.modules.service.PlanFileService;
import com.sdstc.modules.vo.PlanFileTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author ：wk
 * @date ：Created in 2022/11/11 9:47
 */
@RestController
@RequestMapping("/planFile")
public class PlanFileController extends BaseController {

    @Autowired
    private PlanFileService planFileService;

    @PostMapping()
    public AjaxResult savePlanFile(PlanFileEntity planFileEntity){
        planFileService.savePlanFile(planFileEntity, planFileEntity.getFile());
        return AjaxResult.success();
    }

    @PutMapping("/{id}")
    public AjaxResult updatePlanFile(@PathVariable String id, @RequestBody PlanFileEntity planFileEntity){
        planFileService.updatePlanFile(planFileEntity);
        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult deletePlanFile(@PathVariable String id){
        planFileService.deletePlanFile(id);
        return AjaxResult.success();
    }

    @GetMapping("/getPlanFile")
    public AjaxResult getPlanFileList(PlanFileQuery planFileQuery){
        return AjaxResult.success(planFileService.getPlanFileList(planFileQuery));
    }

    @GetMapping("/getPlanFilePage")
    public PlanFileTableVo getPlanFilePage(PlanFileQuery planFileQuery){
        return planFileService.getPlanFilePage(planFileQuery);
    }

    @PostMapping("/downloadPlanFile")
    public void downloadPlanFile(HttpServletResponse response, @RequestBody PlanFileQuery planFileQuery){
        PlanFileUtils.downExportFile(response,planFileQuery.getFilePath());
    }

}
